<?php
declare (strict_types=1);

namespace app\admin\controller;

use think\App;

use app\common\builder\TableBuilder;
use app\common\builder\TableFront;

class Carousel extends Base
{
    //主键，默认为id
    protected $pk = 'id';

    //主模型
    protected $model = '\app\common\model\Carousel';


    public function index()
    {
        return $this->setTable();
    }

    public function setTable()
    {
        //构建table
        $tableFront = TableFront::getInstance()
            ->addRow(['field' => 'id', 'sort' => true, 'title' => 'ID', 'width' => 80])
            ->addRow(['field' => 'title', 'title' => '标题','modify' => 'add|edit','format' => 'input'])
            ->addRow(['field' => 'images', 'title' => '轮播图','width' => 250,
                'templet' => '<div><img class="thumbnail" src="{{d.images}}"/></div>',
                'format' => 'img','modify' => 'add|edit'])
            ->addRow(['field' => 'type', 'title' => '类型'])
            ->addRow(['field' => 'link', 'title' => '链接','modify' => 'add|edit','format' => 'input'])
            ->addRow(['field' => 'sort', 'title' => '排序','width' => 120,'modify' => 'add|edit','format' => 'input',
                'templet' => '<div>
                <input type="text" data-key="sort" data-id="{{d.id}}" data-url="'.url('update').'" value="{{d.sort}}" class="layui-input x-sort tableInput"/>
                </div>'
            ])
            ->addRow(['field' => 'create_time', 'title' => '创建时间'])
            ->addRow(['field' => 'update_time', 'title' => '更新时间'])
            ->addRow(['field' => 'create_time', 'title' => '充值时间'])
            ->addRow(['field' => 'status', 'title' => '状态', 'templet' => '#status', 'width' => 120, 'unresize' => true])
            ->addRow(['fixed' => 'right', 'align' => 'center', 'toolbar' => '#barDemo', 'title' => '操作', 'width' => 200]);

        return TableBuilder::getInstance()
            ->addColumns($tableFront)
            ->addRightButtons(['edit','delete'])
            ->addSwitchTool([['name' => 'status', 'pk' => 'id', 'text' => '开启|关闭']])
            ->addTopButtons(['add'])
            ->setSearch($this->setSearch())
            ->fetch();
    }

    public function setSearch()
    {
        return TableFront::getInstance()
            ->setSearch(['title', '输入轮播标题', 'input','','','','like']);
    }

}
